<?php
/*
 * Класс по аренде домов, участков
 * 
 * */
class Suburbiand_modul  extends CI_Model {
	public $select;
	public $dollars;
 
	public function __construct() {
		// Call the Model constructor
		parent::__construct();

		$this -> fproperty();
		$this-> dollars=30;
	}

	/**
	 * Поиск наглавной главная
	 *
	 * @return void
	 * @author
	 */

	public function request($get = false, $start = 0, $finish = 30) {

		$data = false;
		$select_data = array();
		$DB2 = $this -> load -> database('adsent', TRUE, TRUE);

		$select = "SELECT r.* FROM  `rsuburbian` `r`    
   $get 
   GROUP BY r.id 
   LIMIT $start,$finish;";
		$q = $DB2 -> query($select);

		$data = $this -> req($q);
		return $data;
	}

	public function fproperty() {
		$lt = false;

		$DB2 = $this -> load -> database('adsent', TRUE, TRUE);
		$query = $DB2 -> query("SELECT * FROM `property`");

		if ($query -> num_rows() > 0) {
			foreach ($query->result() as $row) {
				$lt[$row -> text] = $row -> val;
			}
		}
		$this -> property = $lt;
		return;
	}

	/**
	 *
	 * @param $array - массив с данными для разбора
	 *
	 * */
	public function req($datas) {
		$this -> load -> helper('text');
		$this -> load -> helper('see');
		if ($datas -> num_rows() > 0) {

			foreach ($datas -> result() as $row) {
				
 
				$data[] = array('id' => $row -> id, 
				'root' => rent_suburbian_object_type($row -> object_type), 
				'area' => $row -> area, 
				'site' => $row -> site, 
				'r_adress_name' => $row -> adress_name, 
				'r_region_names' => $row -> region_names,
				 'r_region_id' => $row -> region_id, 
				 'r_city_name' => $row -> city_name, 
				 'r_city_id' => $row -> city_id,
				  'r_street_name' => $row -> street_name, 
				 'r_street_id' => $row -> street_id,
				  'r_home_id' => $row -> home_id,
				  'price_dollar' => rent_flat_current($row -> price, $row -> currency,'dollars',$this->dollars),
				   'price_rubley' => rent_flat_current($row -> price, $row -> currency, 'rubley',$this->dollars),
				    'r_for_days' => $row -> for_days, 
				    'r_d_price' => $row -> d_price, 
				    'newtime' => $row -> newtime, 
				    'currency' => $row -> currency, 
				    'r_d_comment' => $row -> d_comment, 
				    'floorn' => $row -> floorn,
				     'comment_client' => $row -> comment_client, 
				     'r_comment_site' => $row -> comment_site,
				      'r_keepday' => $row -> keepday, 
				      'for_day' => rent_suburbian_for_days($row -> for_all),
				       'contact_telefon1' => $row -> contact_telefon1, 
				       'contact_name1' => $row -> contact_name1,
				        'contact_telefon2' => $row -> contact_telefon2, 
				        'contact_name2' => $row -> contact_name2, 
				        'r_id_phone' => $row -> id_phone, 
				        'r_act' => $row -> act,
				         'datetime' => $row -> datetime, 
				        'r_moderator' => $row -> moderator, 
				        'metro' => $row -> name_metro, 
				        'metro_id' => $row -> id_metro, 
				        'adsent' => 'rsuburbian', );
			}
			return $data;
		}
		return 0;
	}

}
